package com.jingwee.fileupload.exception;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

/**
 * @author jingwei
 * @version 1.0
 * @description
 * @date 2023/5/6
 */
@RestControllerAdvice
public class MultipartUploadExceptionHandler {

    @Value("${spring.servlet.multipart.max-file-size}")
    private String fileMaxSize;

    @ExceptionHandler(value = MaxUploadSizeExceededException.class)
    public String fileMaxSize(MaxUploadSizeExceededException e) {
        return String.format("超过上传大小，最大为%s", fileMaxSize);
    }
}
